package com.shejimoshi.工厂方法模式;

import com.shejimoshi.工厂方法模式.common.Video;
import com.shejimoshi.工厂方法模式.例子.JavaVideoFactory;
import com.shejimoshi.工厂方法模式.例子.PythonVideoFactory;
import com.shejimoshi.工厂方法模式.例子.VideoFactory;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        VideoFactory pythonVideoFactory = new PythonVideoFactory();
        Video pythonVideo = pythonVideoFactory.getVideo();
        pythonVideo.produce();

        // 通过反射的方式进行
        String javaVideoFactoryName = "com.shejimoshi.工厂方法模式.例子.JavaVideoFactory";
        VideoFactory javaVideoFactory = (VideoFactory) Class.forName(javaVideoFactoryName).newInstance();
        Video javaVideo = javaVideoFactory.getVideo();
        javaVideo.produce();

        List<Integer> lists = new ArrayList<>();
        Iterator<Integer> iterator = lists.iterator();
        while (iterator.hasNext()) {
            if(iterator.next() == 0) {
                iterator.remove();
            }
        }
    }
}
